package g

import (
	"reflect"
	"testing"
)

// 输入：head = [1], n = 1
// 输出：[]
// 示例 3：

// 输入：head = [1,2], n = 1

func createNode(vals []int) *ListNode {
	head := &ListNode{}
	p := head
	for _, val := range vals {
		p.Next = &ListNode{Val: val}
		p = p.Next
	}
	return head.Next
}

func Test_removeNthFromEnd(t *testing.T) {
	type args struct {
		head *ListNode
		n    int
	}
	tests := []struct {
		name string
		args args
		want *ListNode
	}{
		{"1", args{createNode([]int{1, 2, 3, 4, 5}), 2}, createNode([]int{1, 2, 3, 5})},
		{"2", args{createNode([]int{1}), 1}, createNode([]int{})},
		{"3", args{createNode([]int{1, 2}), 1}, createNode([]int{1})},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := removeNthFromEnd(tt.args.head, tt.args.n); !reflect.DeepEqual(got, tt.want) {
				t.Errorf("removeNthFromEnd() = %v, want %v", got, tt.want)
			}
		})
	}
}
